﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Admin_RoleAdd.aspx.cs" Inherits="Backend_Admin_RoleAdd" %>

<%@ Import Namespace="Wsitech.Model" %>
<%@ Import Namespace="Wsitech.BLL" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="!css/content.css" rel="stylesheet" type="text/css" />
    <script src="!js/jquery-1.7.1.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">
        $(function () {
            //初始化已选择的
            var funIdList = $('[id$=hfFunIdList]').val().split(',');
            for (var idloop = 0; idloop < funIdList.length; idloop++) {
                var funcID = funIdList[idloop];
                if (funcID != '') {
                    $('#' + funcID).attr('checked', 'checked');
                }
            }
            //全选和取消全选
            $('.parent input').change(function () {
                var pid = this.id;
                var children = $('input[name=' + pid + ']');
                if ($(this).attr('checked')) {
                    children.attr('checked', 'checked');
                }
                else {
                    children.removeAttr('checked');
                }
                GetSelectedFunc();
            });
            //有一个子选中时父一定被选中,没有子选中时父不能被选中
            $('.child input').change(function () {
                var pid = this.name;
                var parent = $('#' + pid);
                var children = $('input[name=' + pid + ']');
                var mark = false;
                children.each(function () {
                    if ($(this).attr('checked')) {
                        mark = true;
                        return;
                    }
                });
                if (mark) {
                    parent.attr('checked', 'checked');
                }
                else {
                    parent.removeAttr('checked');
                }
                GetSelectedFunc();
            });

        });
        //已选择的菜单ID列表
        function GetSelectedFunc() {
            var idlist = '';
            $('.funcMenu').each(function (index) {
                if ($(this).attr('checked')) {
                    if (idlist == '') {
                        idlist = this.id;
                    }
                    else {
                        idlist += ',' + this.id;
                    }
                }
            });
            $('[id$=hfFunIdList]').val(idlist);
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div class="content_top">
        <p>
            <label>
                角色名称:
            </label>
            <asp:TextBox runat="server" ID="txtRoleName" class="txt medium" />
        </p>
        <p>
            <label>
                角色描述:
            </label>
            <asp:TextBox runat="server" ID="txtDescription" class="txt" TextMode="MultiLine"
                Rows="3" Columns="40" />
        </p>
        <fieldset>
            <legend>
                <label>
                    权限：
                </label>
            </legend>
            <asp:HiddenField ID="hfFunIdList" runat="server" />
            <asp:Repeater ID="repParentMenu" runat="server">
                <ItemTemplate>
                    <div class="parent">
                        <input class="funcMenu" type="checkbox" id="<%#(Container.DataItem as SiteMapInfo).SitemapId %>" />
                        <label for="<%#(Container.DataItem as SiteMapInfo).SitemapId %>">
                            <%#(Container.DataItem as SiteMapInfo).SitemapName %>
                        </label>
                    </div>
                    <div class="child">
                        <asp:Repeater ID="repMenu" runat="server" DataSource="<%#SiteMapInfoBLL.Instance.GetBackendListByParentId((Container.DataItem as SiteMapInfo).SitemapId) %>">
                            <ItemTemplate>
                                <input class="funcMenu" name="<%#(Container.DataItem as SiteMapInfo).ParentId%>"
                                    type="checkbox" id="<%#(Container.DataItem as SiteMapInfo).SitemapId %>" />
                                <label for="<%#(Container.DataItem as SiteMapInfo).SitemapId %>">
                                    <%#(Container.DataItem as SiteMapInfo).SitemapName %>
                                </label>
                            </ItemTemplate>
                        </asp:Repeater>
                    </div>
                </ItemTemplate>
            </asp:Repeater>
        </fieldset>
        <p>
            <asp:Button Text="确定" ID="btnSubmit" OnClick="btnSubmit_Click" runat="server" />
        </p>
    </div>
    </form>
</body>
</html>
